import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { BaseinfoCompanyApi } from '#/api/csyt/baseinfocompany';

import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'companyId',
      label: '公司标识',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入公司标识',
      },
    },
    {
      fieldName: 'companyName',
      label: '公司名称',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入公司名称',
      },
    },
    {
      fieldName: 'identifier',
      label: '统一社会信用代码',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入统一社会信用代码',
      },
    },
    {
      fieldName: 'type',
      label: '企业类型',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.CSYT_BASEINFO_COMPANY_TYPE, 'number'),
        placeholder: '请选择企业类型',
      },
    },
    {
      fieldName: 'address',
      label: '注册地行政区划代码',
      component: 'Input',
      componentProps: {
        placeholder: '请输入注册地行政区划代码',
      },
    },
    {
      fieldName: 'businessScope',
      label: '经营范围',
      component: 'Input',
      componentProps: {
        placeholder: '请输入经营范围',
      },
    },
    {
      fieldName: 'contactAddress',
      label: '通信地址',
      component: 'Input',
      componentProps: {
        placeholder: '请输入通信地址',
      },
    },
    // {
    //   fieldName: 'economicType',
    //   label: '经营业户经济类',
    //   component: 'Select',
    //   componentProps: {
    //     options: [],
    //     placeholder: '请选择经营业户经济类',
    //   },
    // },
    {
      fieldName: 'regCapital',
      label: '注册资本',
      component: 'Input',
      componentProps: {
        placeholder: '请输入注册资本',
      },
    },
    {
      fieldName: 'legalName',
      label: '法人姓名',
      component: 'Input',
      componentProps: {
        placeholder: '请输入法人姓名',
      },
    },
    // {
    //   fieldName: 'legalId',
    //   label: '法人代农身份证号',
    //   component: 'Input',
    //   componentProps: {
    //     placeholder: '请输入法人代农身份证号',
    //   },
    // },
    {
      fieldName: 'legalPhone',
      label: '法人电话',
      component: 'Input',
      componentProps: {
        placeholder: '请输入法人电话',
      },
    },
    {
      fieldName: 'legalPhoto',
      label: '统一社会信用代码扫描件',
      component: 'Input',
      componentProps: {
        placeholder: '请输入统一社会信用代码扫描件',
      },
    },
    // {
    //   fieldName: 'userId',
    //   label: '用户ID',
    //   component: 'Input',
    //   componentProps: {
    //     placeholder: '请输入用户ID',
    //   },
    // },
    {
      fieldName: 'state',
      label: '状态',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(
          DICT_TYPE.CSYT_BASEINFO_COMPANY_STATE,
          'number',
        ),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    // {
    //   fieldName: 'flag',
    //   label: '1新增2更新3删除',
    //   component: 'RadioGroup',
    //   componentProps: {
    //     options: [],
    //     buttonStyle: 'solid',
    //     optionType: 'button',
    //   },
    // },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'companyName',
      label: '公司名称',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入公司名称',
      },
    },
    {
      fieldName: 'type',
      label: '企业类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_TYPE.CSYT_BASEINFO_COMPANY_TYPE, 'number'),
        placeholder: '请选择企业类型',
      },
    },
    {
      fieldName: 'businessScope',
      label: '经营范围',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入经营范围',
      },
    },
    {
      fieldName: 'legalName',
      label: '法人姓名',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入法人姓名',
      },
    },
    {
      fieldName: 'legalPhone',
      label: '法人电话',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入法人电话',
      },
    },
    // {
    //   fieldName: 'userId',
    //   label: '用户ID',
    //   component: 'Input',
    //   componentProps: {
    //     allowClear: true,
    //     placeholder: '请输入用户ID',
    //   },
    // },
    // {
    //   fieldName: 'state',
    //   label: '0有效1无效',
    //   component: 'Select',
    //   componentProps: {
    //     allowClear: true,
    //     options: [],
    //     placeholder: '请选择0有效1无效',
    //   },
    // },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<BaseinfoCompanyApi.BaseinfoCompany>['columns'] {
  return [
    { type: 'checkbox', width: 40 },
    {
      field: 'id',
      title: '编号',
      minWidth: 120,
    },
    {
      field: 'companyId',
      title: '公司标识',
      minWidth: 120,
    },
    {
      field: 'companyName',
      title: '公司名称',
      minWidth: 120,
    },
    {
      field: 'identifier',
      title: '统一社会信用代码',
      minWidth: 120,
    },
    {
      field: 'type',
      title: '企业类型',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.CSYT_BASEINFO_COMPANY_TYPE },
      },
    },
    {
      field: 'address',
      title: '注册地行政区划代码',
      minWidth: 120,
    },
    {
      field: 'businessScope',
      title: '经营范围',
      minWidth: 120,
    },
    {
      field: 'contactAddress',
      title: '通信地址',
      minWidth: 120,
    },
    // {
    //   field: 'economicType',
    //   title: '经营业户经济类',
    //   minWidth: 120,
    // },
    {
      field: 'regCapital',
      title: '注册资本',
      minWidth: 120,
    },
    {
      field: 'legalName',
      title: '法人姓名',
      minWidth: 120,
    },
    // {
    //   field: 'legalId',
    //   title: '法人代农身份证号',
    //   minWidth: 120,
    // },
    {
      field: 'legalPhone',
      title: '法人电话',
      minWidth: 120,
    },
    {
      field: 'legalPhoto',
      title: '统一社会信用代码扫描件',
      minWidth: 120,
    },
    {
      field: 'userId',
      title: '用户ID',
      minWidth: 120,
    },
    // {
    //   field: 'state',
    //   title: '0有效1无效',
    //   minWidth: 120,
    // },
    // {
    //   field: 'flag',
    //   title: '1新增2更新3删除',
    //   minWidth: 120,
    // },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
